package com.lsu.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsu.app.bean.Praise;
import com.lsu.app.service.PraiseService;
import com.lsu.app.mapper.PraiseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @description 针对表【praise(点赞表)】的数据库操作Service实现
 * @Date 2023-10-27 11:01:29
 * @author hjj
 */
@Transactional
@Service
public class PraiseServiceImpl extends ServiceImpl<PraiseMapper, Praise> implements PraiseService{
    private final PraiseMapper mapper;
    private HttpServletRequest request;

    public PraiseServiceImpl(PraiseMapper mapper, HttpServletRequest request) {
        this.mapper = mapper;
        this.request = request;
    }

    @Override
    public Praise getOneByUserIdAndTypeAndTargetId(Integer userId, Integer type, Integer targetId) {
        return mapper.getOneByUserIdAndTypeAndTargetId(userId, type, targetId);
    }

    @Override
    public Integer getNumByTypeAndTargetId(Integer type, Integer targetId) {
        return mapper.getNumByTypeAndTargetId(type,targetId);
    }

    @Override
    public Integer getSelfLike(Integer targetId, Integer type) {
        return mapper.getSelfLike((Integer) request.getSession().getAttribute("id"), targetId, type);
    }

}




